/*
 * Copyright (c)$today.year.month.day
 *  admin:郑程荣.
 *  文件名:IpDialog.java
 *  项目功能:
 */

package com.jg.myproject.widget.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;

import com.jg.myproject.api.Const;
import com.jg.myproject.utils.RxSPTool;
import com.jg.myproject.utils.ScreenUtil;
import com.zcr.myproject.R;


/**
 * @author CD
 *         show
 */
public class IpDialog extends Dialog {

    Context context;


    public IpDialog(Context context) {
        this(context, R.style.enterDialog);
        this.context = context;
    }
    public IpDialog(Context context, int theme) {
        super(context, theme);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_ip_dialog);
        Window window = getWindow();
        WindowManager.LayoutParams wl = window.getAttributes();
        wl.alpha = 1.0f;
        wl.gravity = Gravity.CENTER;
        wl.width = ScreenUtil.getScreenWidth(context);
        window.setAttributes(wl);
        setCancelable(true);
        setCanceledOnTouchOutside(true);

        final EditText host=findViewById(R.id.host);
        final EditText port=findViewById(R.id.port);

        host.setText(TextUtils.isEmpty(RxSPTool.getString(context, "HOST"))?"120.77.59.176":RxSPTool.getString(context, "HOST"));
        port.setText(TextUtils.isEmpty(RxSPTool.getString(context, "PORT"))?"8030":RxSPTool.getString(context, "PORT"));

        findViewById(R.id.enter).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                RxSPTool.putString(context, "HOST",TextUtils.isEmpty( host.getText().toString())?"120.77.59.176": host.getText().toString());
                RxSPTool.putString(context, "PORT", TextUtils.isEmpty(port.getText().toString())?"8030":port.getText().toString());
                //拼接url传参 存入缓存
                Const.weburl="http://"+host.getText().toString().trim()+":"+port.getText().toString().trim()+"/";
                RxSPTool.putString(context, "BASEURL", Const.weburl);
                dismiss();
            }
        });
    }
}
